package com.alibaba.citrus.cr.platform.enhance.functions.item.group;

import com.alibaba.citrus.cr.common.util.SpringContextUtil;
import com.alibaba.citrus.cr.platform.enhance.repository.ScItemGroupRepository;

import com.epoch.app.crplatformenhance.dto.request.IdQueryRequest;
import com.epoch.app.crplatformenhance.dto.request.QueryScItemGroupRequest;
import com.epoch.app.crplatformenhance.dto.response.ScItemGroupResponse;
import com.epoch.app.crplatformenhance.sdo.ScItemGroupSDO;
import lombok.Getter;
import lombok.Setter;

/**
 * @author zhoubc
 * @description: TODO
 * @date 2021/9/3 20:05
 */
public class ScItemGroupEntity {

    @Getter
    @Setter
    private ScItemGroupSDO scItemGroupSDO;

    private static ScItemGroupRepository scItemGroupRepository;

    static {
        scItemGroupRepository = SpringContextUtil.getBean(ScItemGroupRepository.class);
    }

    public static ScItemGroupEntity of(ScItemGroupSDO scItemGroupSDO) {
        ScItemGroupEntity entity = new ScItemGroupEntity();
        entity.setScItemGroupSDO(scItemGroupSDO);
        return entity;
    }

    public String doCreate() {
        return scItemGroupRepository.createScItemGroup(scItemGroupSDO);
    }

    public Boolean doEdit() {
        return scItemGroupRepository.editScItemGroup(scItemGroupSDO);
    }

    public ScItemGroupResponse doQueryById(IdQueryRequest request) {
        return scItemGroupRepository.getScItemGroupById(request.getId());
    }

    public ScItemGroupResponse doQuery(QueryScItemGroupRequest request) {
        ScItemGroupResponse response = scItemGroupRepository.getScItemGroup(request);
        if (!"11".equals(response.getCode())) {
            return new ScItemGroupResponse();
        }
        return response;
    }
}
